package net.neptech.service.impl;

import net.neptech.model.information.InforArticle;
import net.neptech.repository.InforArticleRepository;
import net.neptech.service.InforArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author 谢辉
 * @Date 2025/8/21 10:15
 * @Description TODO
 **/
@Service
public class InforArticleServiceImpl implements InforArticleService {

    @Autowired
    InforArticleRepository inforArticleRepository;

    @Override
    public void addArticle(InforArticle inforArticle) {
        inforArticle.setPublishTime(new Date());
        inforArticleRepository.save(inforArticle);

    }

    @Override
    public void deleteArticle(Long id) {
        //根据id查到文章
        InforArticle inforArticle = inforArticleRepository.findById(id).get();
        //修改文章状态
        inforArticle.setStatus(0);
        //保存
        inforArticleRepository.save(inforArticle);
    }

    @Override
    public List<InforArticle> findArticle() {
        return inforArticleRepository.findAllByStatus(1);
    }

    @Override
    public void updateArticle(InforArticle inforArticle) {
        inforArticle.setPublishTime(new Date());
        inforArticleRepository.save(inforArticle);
    }

    @Override
    public InforArticle findArticleById(Long id) {
        return inforArticleRepository.findById(id).get();
    }


}
